<?php
include_once 'fns.php';
include_once 'admin_html.php';
include_once 'pdf.php';

abstract class PB_View {
    protected $id_let;
    protected $globalsearch;
    protected $id_org;
    protected $id_dep;
    protected $tel_ood;

//    private $link_pdf='';

    protected function __construct($id_let,$globalsearch,array $tel_ood) {
        $this->id_let=$id_let;
        $this->globalsearch=$globalsearch;
        $this->id_org=$tel_ood[0];
        $this->id_dep=$tel_ood[1];
        $this->tel_ood=$tel_ood;
    }
    static function getInstance($id_let,$globalsearch,$tel_ood){
        if (is_null($id_let) && is_null($globalsearch)) return new PB_View_content($id_let,$globalsearch,$tel_ood);
        else 
            if (is_null($globalsearch)) return new PB_View_let($id_let,$globalsearch,$tel_ood);
            else return new PB_View_cardemp($id_let,$globalsearch,$tel_ood);
    }
    abstract function pb_view_content();
    abstract function create_pdf();
    abstract function getLink_pdf();
}

class PB_View_content extends PB_View {
    private $name_org;
    private $name_dep_pdf;
    function __construct($id_let, $globalsearch, $tel_ood) {
        parent::__construct($id_let, $globalsearch, $tel_ood);
        $f1=$this->tel_ood[2];
        $f2=  $this->id_dep;        
        if (!empty($this->tel_ood[2]) && $this->id_dep!=0) {
            $dep_tmp=get_dep($this->id_dep);
            $this->name_dep_pdf='<h4>'.$dep_tmp[0][1].' (Тел. '.formated_tel($this->tel_ood[2]).')</h4>';        
        }        
        $this->name_org=applogic_name_org(get_org($this->id_org),  $tel_ood);
    }
    function pb_view_content() {
        
        pb_view_content(pb_org($this->id_org), pb_emp($this->id_dep,$this->id_org,$this->id_let),  $this->name_org,pb_dep($this->id_org, $this->id_dep,$this->tel_ood[2]),$this->getLink_pdf());
    }
    function create_pdf() {
        create_pdf($this->name_org,$this->name_dep_pdf,pb_emp($this->id_dep,$this->id_org,$this->id_let));
    }
    function getLink_pdf() {
        return '<div style="float:right;"><a href="index.php?action=pdf&org='.$this->id_org.'&dep='.$this->id_dep.'" title="Получить текущую страницу в PDF"><img src="img/pdf.png" /></a></div>';
    }
}

class PB_View_let extends PB_View {
    function pb_view_content() {
        pb_view_content1($this->id_let,pb_emp($this->id_dep,$this->id_org,$this->id_let),pb_org($this->id_org),$this->getLink_pdf());
    }
    function create_pdf() {
        create_pdf("<h4>Сотрудники на букву ".$this->id_let."</h4>",NULL,pb_emp($this->id_dep,$this->id_org,$this->id_let));
    }
    function getLink_pdf() {
        return '<div style="float:right;"><a href="index.php?action=pdf&let='.$this->id_let.'" title="Получить текущую страницу в PDF"><img src="img/pdf.png" /></a></div>';;
    }    
}

class PB_View_cardemp extends PB_View {
    function pb_view_content() {
        pb_view_content2(pb_org($this->id_org),privat_card_emp($this->globalsearch),$this->getLink_pdf());
    }
    function create_pdf() {
        create_pdf(NULL,NULL,privat_card_emp($this->globalsearch));
    }
    function getLink_pdf() {
        return '<div style="float:right;"><a href="index.php?action=pdf&globalsearch='.$this->globalsearch.'" title="Получить текущую страницу в PDF"><img src="img/pdf.png" /></a></div>';
    }    
}
?>
